<?php

namespace app\common\model\shoppay;

use app\common\model\CommonModel;
use think\facade\Db;


class ShoppayTerminalModel extends CommonModel{

    protected  $name = 'shop_pay_terminal';

    protected  $pk   = 'id';


    public static function info($where){
        $where['is_delete']=0;
        $info =self::where($where)->find();
        return $info;
    }
    public static function list($where,$order,$page=1,$limit=10){
        $query = Db::name('shop_pay_terminal')->alias('a')
            ->where(['a.is_delete'=>0])
            ->when(!empty($where['shop_id']),function ($query) use ($where){
                $query->where(['a.shop_id'=>$where['shop_id']]);
            })
            ->when(!empty($where['number']),function ($query) use ($where){
                $query->where('a.number','like','%'.$where['number'].'%');
            })
            ->when(!empty($where['terminal_num']),function ($query) use ($where){
                $query->where('a.terminal_num','like','%'.$where['terminal_num'].'%');
            })
            ->field("a.*");
        $count=$query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        return compact('count','list');
    }
    public static function up($data,$where){
        $data['edit_time']=date('Y-m-d H:i:s');
        $res=self::update($data,$where);
        return $res;
    }
}

